<?php

$json_data = array(
	'Commoditys' => array(
		"warehouseCode" => "FLHZ01",
		"commodityCode" => "150987650012",
		"commodityName" => "测试商品名称12",
		"commoditySpec" => "1台",
		"commodityArtNo" => '',
		"commodityMadeTime" => '',
		"durabilityPeriod" => '',
		"brandId" => '',
		"brandName" => '',
		"price" => '',
		"marketPrice" => '',
		"lotControl" => '',
		"serialcontrol" => "",
		'typeId' => '',
		'typeName' => '',
		"unit" => "001",
		"weight" => "1.00",
		'boxSpec' => '',
		'remark' => '',
		'madeAddr' => '',
		"tradeCountryName" => "亚州",
		"tradeCountryCode " => "100",
		'HScode' => ''
	)
);
$json_data = json_encode($json_data);
// 
// 
//order

// $json_data = array(
// 	"Orders" => array(
// 		array(
// 		"orderCode" => "123456789222000",
// 		"orderDate" => date('Y-m-d H:i:s'),
// 		"outCode" => '',
// 		"expressName" => '',
// 		"expressNo" => '',
// 		"receiverName" => 'test_receiver',
// 		"buyernick" => '',
// 		"mobile" => '13598604597',
// 		"warehouseCode" => 'FLHZ01',
// 		"shopid" => '',
// 		"shop" => '',
// 		"buyerMessage" => '',
// 		"remark" => '',
// 		"systemRemark" => '',
// 		"telPhone" => '',
// 		"province" => "河南",
// 		"city" => '新乡',
// 		"district" => '红旗区',
// 		"receiverAddress" => '测试地址',
// 		"receiverZip" =>'',
// 		"isCashOnDelivery" => '',
// 		"payType" => '01',
// 		"payCompanyCode" => '',
// 		"payNumber" => '',
// 		"orderTotalAmount" => '120.00',
// 		"orderGoodsAmount" => '120.00',
// 		"orderTaxAmount" => '0',
// 		"feeAmount" => '0',
// 		"tradeTime" => date('Y-m-d H:i:s'),
// 		"currCode" => '142',
// 		"totalAmount" => '120.00',
// 		"purchaserId" => '1',
// 		"id" => 1,
// 		"name" => 'testbin',
// 		"telNumber" => "13598604597",
// 		"paperType" => '01',
// 		"paperNumber" => '410703199103263035',
// 		"address" => '测试地址',
// 		"OrderDtls" => array(
// 			array(
// 				"commodityCode" => "150987650001",
// 				"commodityName" => '测试商品名称',
// 				"commodityBarcode" => "",
// 				"commoditySpec" => '1台',
// 				"isSet" => '',
// 				"qty" => '1',
// 				"weight" => '1.00',
// 				"buyerMessage" => '',
// 				"remark" => '',
// 				"tradePrice" => '120.00',
// 				"tradeTotal" => '120.00',
// 				"declPrice" => '120.00',
// 				"declTotalPrice" => '120.00',
// 				"codeTs" => "07010290"
// 			)
// 		),
// 	  ),
// 	),
// );

print_r($json_data);

$json_data = json_encode($json_data);


echo $json_data;


$json_data = '{"Commoditys": [
{
        "warehouseCode" : "FLHZ01",
		"commodityCode":"150987650001",
		"commodityName":"测试商品名称",
		"commoditySpec":"1台",
		"unit":"001",
		"weight":"1.00",
		"tradeCountryName":"亚州",
		"tradeCountryCode ":"100"
 
 }
]
}';

$param = array();
$param['v'] = '1.0';
$param['ip'] = '127.0.0.1';
$param['sessionKey'] = '2015SPWLAV1';
$param['datetime'] = date('YmdHis');
// $param['appKey'] = 'SPWL';
// $sign = implode($param);
$sign = $param['v'] . $param['ip'] . $param['sessionKey'] . $param['datetime'] . 'SPWLA';
echo $sign;
$sign = strtoupper(md5(($sign)));


$param['sign'] = $sign;
$param['JSON_OBJ'] = base64_encode($json_data);


$url = 'http://60.191.39.196:8001/ecm/interface/rest/SPWLInterface/sendCommodity';
// $url = 'http://60.191.39.196:8001/ecm/interface/rest/SPWLInterface/pushSaleOrder';
function file_get_contents_post($url, $post) {  
	    $options = array(  
	        'http' => array(  
	            'method' => 'POST',  
	            // 'content' => 'name=caiknife&email=caiknife@gmail.com',  
	            'content' => http_build_query($post),  
	        ),  
	    );  
	  
	    $result = file_get_contents($url, false, stream_context_create($options));  
	  
	    return $result;  
	}  

echo PHP_EOL;
print_r($param);
function post_get($url,$arr){
	$post_data = array();
	foreach($arr as $key => $val){
		$post_data[] = "$key=$val";
	}
    $post_data = implode('&',$post_data);  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_POST, 1);  
    curl_setopt($ch, CURLOPT_URL,$url);  
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);  
    ob_start();  
    curl_exec($ch);  
    $result = ob_get_contents() ;  
    ob_end_clean(); 
    return $result;
}
echo post_get($url,$param);

